package myTest.syntax

import myTest.classAndInterface.Person
import myTest.enumPackage.Color
import myTest.enumPackage.Gender

class When {

    /**
     *
     * when可以使用任意对象
     *
     * 不带val,var
     *
     * fun():xxx{return xxx}相当于fun()=xxx
     *
     */
    fun getColorStr(color: Color) =
            when (color) {
                Color.RED -> "红色"
                Color.YELLOW -> "黄色"
            }

    fun mix(p1: Person, p2: Int) =
            when (setOf(p1, p2)) {
            //setOf()函数无关参数位置顺序
                setOf(666,
                        Person(1, "董棉生", Gender.MAN)
//                        Person(2, "田馥甄", Gender.WOMEN)
                ) -> "匹配"
                else -> "找不到"
            }

    /**
     * when后可以不带()，分支条件是任意的布尔表达式
     */
    fun getGender(gender: Gender)=
    when{
        gender==Gender.MAN->"我是男人"
        gender==Gender.WOMEN->"妹子"
        else->"不详"
    }

}


fun main(args: Array<String>) {
    println(When().getColorStr(Color.YELLOW))
    println(When().mix(
//            Person(2, "田馥甄", Gender.WOMEN),
            Person(1, "董棉生", Gender.MAN),
            666
    ))

    println(When().getGender(Gender.WOMEN))
}
